package com.flink.mybatis;

import java.io.InputStream;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class ConnTool {

    static SqlSessionFactory sqlSessionFactory = null;
    static{
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
        try {
            InputStream xmlurl = ConnTool.class.getResourceAsStream("/myconfig.xml");
            //URL res = ConnTool.class.getResource("/myconfig.xml");
            
            
            if(xmlurl != null)
                sqlSessionFactory = sqlSessionFactoryBuilder.build( xmlurl );
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static SqlSession getSession(){
        return sqlSessionFactory.openSession(true);
    }
    
}